﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Business.Dal;
using Business.Entity;

namespace Sahibinden.UserControl
{
    public partial class login : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Page.User.Identity.IsAuthenticated)
            {
                pnlLogin.Visible = false;
                pnlSignOut.Visible = true;

                UyeProvider uyep = new UyeProvider();
                Uye uye = uyep.GetUyeGetirID(Convert.ToInt32(Page.User.Identity.Name));
                lblName.Text = uye.Adi + " " + uye.Soyadi;

                MesajSayisiGetir();
            }

            else
            {
                pnlLogin.Visible = true;
                pnlSignOut.Visible = false;

            }

        }

        private void MesajSayisiGetir()
        {
            if(Page.User.Identity.IsAuthenticated)
            {
            MesajProvider mp = new MesajProvider();
          lblYeniMesaj.Text=  mp.MesajlarOkunmamislariGetir(Convert.ToInt32(Page.User.Identity.Name)).Count.ToString();
            }
        }

        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {

            Business.Dal.UyeProvider uye = new Business.Dal.UyeProvider();
            int UyeID = uye.Login(txtAdi.Text, txtSifre.Text);
            if (UyeID != 0)
            {
                FormsAuthentication.RedirectFromLoginPage(UyeID.ToString(), CheckBox1.Checked);
            }
        }

        protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
        {
            FormsAuthentication.SignOut();
            Response.Redirect("Default.aspx");
        }
    }
}